package com.algorithm.thePrimaryAlgorithm;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

@Slf4j
public class StringSulotionLC13 {
    public int reverse(int x) {
        int res = 0;
        while (x != 0) {
            int old = res;
            res = res * 10 + x % 10;
            //通过反向运算看看是否溢出
            if ((res - x % 10) / 10 != old) {
                return 0;
            }
            x /= 10;
        }
        return res;
    }

    @Test
    public void test(){
        int reverse = reverse(-123);
        log.info("over {}",reverse);
    }


}
